package com.tiany.kotlin_study

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_third.*

class ThirdActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_third)
        supportActionBar?.hide()//隐藏自带的标题栏

        /* 拨号
        thi_btn1.setOnClickListener {
            val intent=Intent(Intent.ACTION_DIAL)
            intent.data= Uri.parse("tel:10086")
            startActivity(intent)
        }*/

        //控制环形条的可见性
        thi_btn2.setOnClickListener {
            if (pb1.visibility == View.VISIBLE)
                pb1.visibility = View.GONE
            else
                pb1.visibility = View.VISIBLE
        }

        //进度条加10
        thi_iv1.setOnClickListener {
            pb2.progress += 10
        }

        //按钮1的带年纪事件
        thi_btn1.setOnClickListener {
            /*  接收数据
            val data=intent.getStringExtra("extr_data1")
            Toast.makeText(this,data,Toast.LENGTH_SHORT).show()*/
            val intent = Intent()
            intent.putExtra("data_return", "username")
            setResult(RESULT_OK, intent)
            finish()
        }

        //对话框
        thi_btn3.setOnClickListener {
            AlertDialog.Builder(this).apply {
                setTitle("对话框")
                setMessage("对话框信息")
                setCancelable(false)
                setPositiveButton("确定") { dialog, which ->
                    Toast.makeText(this@ThirdActivity, "hhh", Toast.LENGTH_SHORT).show()
                }
                setNegativeButton("返回") { dialog, which -> }
                show()
            }
        }
        //跳转到界面四
        thi_btn4.setOnClickListener {
            val intent = Intent(this, FourthActivity::class.java)
            startActivity(intent)

        }
    }
}